/* SPDX-License-Identifier: GPL-2.0 */

#ifndef	DIM_UTILS_H
#define	DIM_UTILS_H

#include <linux/types.h>
#include <linux/mm_types.h>

#define MAX_BUFFER_SIZE (1024 * 1024)

/**
 * dim_path_join - return joined path from dir name and filename
 * @dir: a pointer to directory name string
 * @file: a pointer to file name string
 *
 * Returns: a pointer to joined path (should be freed by kfree) or
 * errno on failure (via ERR_PTR).
 */
char *dim_path_join(const char *dir, const char *file);

/**
 * dim_filename_has_ext - check if a filename has specified ext
 * @filename: a pointer to file name string
 * @ext: a pointer to ext name string
 *
 * Returns: true of false
 */
bool dim_filename_has_ext(const char *filename, const char *ext);

/**
 * dim_digest_compare - compare two digest array
 * @data1: a pointer to digest data
 * @data2: a pointer to digest data
 * @len: compare length
 *
 * Caller must ensure that the parameters is are empty.
 *
 * Returns: 0 for equal, -1 or 1 for unequal
 */
int dim_digest_compare(unsigned char *data1,
		       unsigned char *data2,
		       unsigned int len);

/**
 * dim_string_to_hex - change string to hex array
 * @str: a pointer to string
 * @str_len: length of str
 * @buf: a pointer to buf
 * @buf_len: length of buf
 *
 * Returns: 0 on success or -errno on failure
 */
int dim_string_to_hex(const char *str,
		      int str_len,
		      unsigned char *buf,
		      int buf_len);

/**
 * dim_hex_to_string - change hex array to string
 * @data: hex array
 * @data_len: length of data
 * @buf: string buf
 * @buf_len: length of buf
 *
 * Returns: 0 on success or -errno on failure
 */
int dim_hex_to_string(unsigned char *data,
		      int data_len,
		      char *buf,
		      int buf_len);

/**
 * dim_get_absolute_path - get real path of given path
 * @name: file path to be read
 * @buf: path buffer to be used
 * @len: length of buf
 *
 * Returns: pointer to realpath or errno (via ERR_PTR)
 */
char *dim_get_absolute_path(const char *name, char *buf, int len);

struct file *dim_get_vma_file(struct vm_area_struct *vma);

#endif /* DIM_UTILS_H */
